package com.qms.tubu.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.qms.tubu.R;
import com.qms.tubu.bean.ModuleBean;

/**
 * Created by Mad on 2015/7/17.
 */
public class ModuleAdapter extends LoadMoreAdapter<ModuleBean>{
    private Activity mActivity;
    public HeadHolder mHeadHolder;
    public ModuleAdapter(Activity activity, GridLayoutManager layoutManager, boolean hasHead) {
        super(activity, layoutManager, hasHead);
        this.mActivity=activity;
        for(int i=0;i<100;i++)
            mList.add(new ModuleBean());
    }

    @Override
    public int getItemViewType(int position) {
        if(position==0)
            return 1;
        else if(position==getItemCount()-1)
            return super.getItemViewType(position);
        else
            return 0;

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(viewType==1)
        {
            View view= LayoutInflater.from(mContent).inflate(R.layout.module_detail_head,parent,false);
            mHeadHolder=new HeadHolder(view);
            return mHeadHolder;
        }
        else if(viewType==-1)
            return super.onCreateViewHolder(parent, viewType);
        else
        {
            View view=LayoutInflater.from(mContent).inflate(R.layout.module_scenic_item,parent,false);
            return new ScenicHolder(view);
        }
    }

    public HeadHolder getHeadHolder() {
        return mHeadHolder;
    }

    @Override
    public int getItemCount() {
        return 2+mList.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if(position==0)
        {
            HeadHolder headHolder= (HeadHolder) holder;
            Glide.with(mActivity).load("http://q.qlogo.cn/qqapp/1104627204/02A5CFF1A13BC60BD1BC9934B7436841/100")
                    .centerCrop().crossFade()
                    .into(headHolder.image);
        }
        else if(position<getItemCount()-1)
        {
            ScenicHolder scenicHolder= (ScenicHolder) holder;
            Glide.with(mActivity).load("http://qianmosen.cn/tubu/Public/Upload/otherScenic/76fa38a4a03be77920f208f18a4195f12.jpg")
                    .centerCrop().crossFade()
                    .into(scenicHolder.image);
        }


    }
    public static class HeadHolder extends RecyclerView.ViewHolder{
        private ImageView image;

        public HeadHolder(View itemView) {
            super(itemView);
            image= (ImageView) itemView.findViewById(R.id.module_image);
        }

        public ImageView getImage() {
            return image;
        }
    }
    public static class ScenicHolder extends RecyclerView.ViewHolder{
        private ImageView image;
        public ScenicHolder(View itemView) {
            super(itemView);
            image= (ImageView) itemView.findViewById(R.id.scenic_image);
        }
    }

}
